package com.tl.sboot.conf;

import org.springframework.beans.factory.annotation.Autowired;  
import org.springframework.beans.factory.annotation.Qualifier;  
import org.springframework.beans.factory.annotation.Value;  
import org.springframework.context.annotation.Bean;  
import org.springframework.context.annotation.Configuration;  
  
import redis.clients.jedis.JedisPool;  
import redis.clients.jedis.JedisPoolConfig;  
  
@Configuration  
public class RedisConfiguration {  
    /**
     * 连接 
     * @param config
     * @param host
     * @param maxWaitMillis
     * @param port
     * @param password
     * @return
     */
    @Bean(name= "pool.a")  
    @Autowired  
    public JedisPool jedisPool(@Qualifier("jedis.pool.config") JedisPoolConfig config,   
                @Value("${spring.redis.host}")String host, 
                @Value("${spring.redis.timeout}")int timeout,
                @Value("${spring.redis.port}")int port,
                @Value("${spring.redis.password}") String password) { 
        JedisPool jedisPool = new JedisPool(config, host, port,timeout,password);
        System.out.println(jedisPool);
		return jedisPool;  
    }  
    /**
     * 配置jedis数据库连接池 
     * @param maxTotal
     * @param maxIdle
     * @param maxWaitMillis
     * @return
     */
    @Bean(name= "jedis.pool.config")  
    public JedisPoolConfig jedisPoolConfig (@Value("${spring.redis.pool.max-total}")int maxTotal,  
                                @Value("${spring.redis.pool.max-idle}")int maxIdle,  
                                @Value("${spring.redis.pool.max-waitMillis}")int maxWaitMillis) {  
        JedisPoolConfig config = new JedisPoolConfig();  
        config.setMaxTotal(maxTotal);  
        config.setMaxIdle(maxIdle);  
        config.setMaxWaitMillis(maxWaitMillis);  
        return config;  
    }  
      
}  